#include "qenhancedgraphicsview.h"

QEnhancedGraphicsView::QEnhancedGraphicsView(QWidget *parent)
    : QGraphicsView(parent)
{

}


void QEnhancedGraphicsView::wheelEvent(QWheelEvent *event)
{
    QPoint numDegrees = event->angleDelta();
    if(!numDegrees.isNull())
    {
        double angelDeltaY = numDegrees.y();
        double zoomFactor = qPow(1.0015, angelDeltaY);
        scale(zoomFactor, zoomFactor);

        if(angelDeltaY > 0)
        {
            this->centerOn(sceneMousePos);
            sceneMousePos = this->mapToScene(event->position().toPoint());
        }
        this->viewport()->update();
        event->accept();
    }
    else
    {
        event->ignore();
    }
}
